class Solution:
    def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:
        cocon = set()
        # 寻找不能沟通的好友
        for friendship in friendships:
            mp = {}
            conm = False
            for lan in languages[friendship[0] - 1]:
                mp[lan] = 1
            for lan in languages[friendship[1] - 1]:
                if lan in mp:
                    conm = True
                    break
            if not conm:
                cocon.add(friendship[0] - 1)
                cocon.add(friendship[1] - 1)
        
        max_cnt = 0
        cnt = [0] * (n + 1)
        for friendship in cocon:
            for lan in languages[friendship]:
                cnt[lan] += 1
                # 掌握最多的语言
                max_cnt = max(max_cnt, cnt[lan])
        
        return len(cocon) - max_cnt